package com.runqian.base.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;



public class RSA {

	public byte[] process(byte[] is) {
		if(is!=null){
			ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(1024);
			if (_$1)
				is = _$1(is);
			try {
				int i = 0;
				while (i < is.length) {
					if (is.length - i - _$4 > 0) {
						bytearrayoutputstream.write(_$1(is, i, _$4));
						i += _$4;
					} else {
						bytearrayoutputstream.write(_$1(is, i, is.length - i));
						i = is.length;
					}
				}
			} catch (java.io.IOException ioexception) {
				/* empty */
			}
			byte[] is_20_ = bytearrayoutputstream.toByteArray();
			if (!_$1)
				is_20_ = _$2(is_20_);
		}
		CredWriter cw = new CredWriter();
		cw.writeShort(2);
		cw.writeChars("报表 3.5");
		cw.writeByte(22);
		cw.writeByte(1);
		cw.writeChars("软件公司");
		cw.writeChars("http://www.hhkj.cn");
		cw.writeChars("(0371) 67372578 路电：05326666-67372578");
		cw.writeShort(-1);
		cw.writeByte(0);
		cw.writeChars("信息系统");
		cw.writeChars("信息系统");
		cw.writeChars("");
		cw.writeChars("");//版权信息
		cw.writeChars("");//授权的操作系统类型。如：Windows,Linux等，为空字符串时可在所有系统下使用
		cw.writeChars("");
		cw.writeLong(-1);//版权截止日期，为-1是永远不到期，否则使用类似DateUtil.parse("2020-01-01").getTime()写进去。
		cw.writeChars("");
		cw.writeShort(1);
		cw.writeShort(-1);
		cw.writeShort(-1);
		cw.writeChars("2000 - 2006");
		return cw.getBytes();
//*		return is_20_;
		//无期限限制，且无“内部开发，禁止传播与使用”
//		return new byte[]{0,2,0,8,109,-90,78,126,98,-91,-120,104,0,32,0,51,0,46,0,53,22,1,0,12,83,23,78,-84,109,-90,78,126,-113,111,78,-10,98,-128,103,47,103,9,-106,80,81,108,83,-8,0,25,0,104,0,116,0,116,0,112,0,58,0,47,0,47,0,119,0,119,0,119,0,46,0,114,0,117,0,110,0,113,0,105,0,97,0,110,0,46,0,99,0,111,0,109,0,46,0,99,0,110,0,15,0,40,0,48,0,49,0,48,0,41,0,32,0,53,0,49,0,54,0,54,0,32,0,56,0,52,0,52,0,49,-1,-1,0,0,11,-108,-63,-112,83,-112,-24,117,53,82,-95,123,-95,116,6,79,-31,96,111,124,-5,126,-33,0,11,-108,-63,-112,83,-112,-24,117,53,82,-95,123,-95,116,6,79,-31,96,111,124,-5,126,-33,0,0,0,
//    			0,0,7,0,87,0,105,0,110,0,100,0,111,0,119,0,115,0,0,
//    			-1,-1,-1,-1,-1,-1,-1,-1,
//    			0,0,0,1,-1,-1,-1,-1,0,11,0,50,0,48,0,48,0,48,0,32,0,45,0,32,0,50,0,48,0,48,0,54};
/*
		//期限至2042年，有“内部开发，禁止传播与使用”
		return new byte[]{0,2,0,8,109,-90,78,126,98,-91,-120,104,0,32,0,51,0,46,0,53,22,1,0,12,83,23,78,-84,109,-90,78,126,-113,111,78,-10,98,-128,103,47,103,9,-106,80,81,108,83,-8,0,25,0,104,0,116,0,116,0,112,0,58,0,47,0,47,0,119,0,119,0,119,0,46,0,114,0,117,0,110,0,113,0,105,0,97,0,110,0,46,0,99,0,111,0,109,0,46,0,99,0,110,0,15,0,40,0,48,0,49,0,48,0,41,0,32,0,53,0,49,0,54,0,54,0,32,0,56,0,52,0,52,0,49,-1,-1,0,0,11,-108,-63,-112,83,-112,-24,117,53,82,-95,123,-95,116,6,79,-31,96,111,124,-5,126,-33,0,11,-108,-63,-112,83,-112,-24,117,53,82,-95,123,-95,116,6,79,-31,96,111,124,-5,126,-33,0,0,0,14,81,-123,-112,-24,95,0,83,-47,79,127,117,40,0,44,78,37,121,-127,79,32,100,-83,78,14,-107,0,85,46,0,7,0,87,0,105,0,110,0,100,0,111,0,119,0,115,0,0,
    			0,0,2,23,43,-57,-12,0,
    			0,0,0,1,-1,-1,-1,-1,0,11,0,50,0,48,0,48,0,48,0,32,0,45,0,32,0,50,0,48,0,48,0,54};
	*/
		/*
		//期限至2008-06-01，有“内部开发，禁止传播与使用”
		return new byte[]{0,2,0,8,109,-90,78,126,98,-91,-120,104,0,32,0,51,0,46,0,53,22,1,0,12,83,23,78,-84,109,-90,78,126,-113,111,78,-10,98,-128,103,47,103,9,-106,80,81,108,83,-8,0,25,0,104,0,116,0,116,0,112,0,58,0,47,0,47,0,119,0,119,0,119,0,46,0,114,0,117,0,110,0,113,0,105,0,97,0,110,0,46,0,99,0,111,0,109,0,46,0,99,0,110,0,15,0,40,0,48,0,49,0,48,0,41,0,32,0,53,0,49,0,54,0,54,0,32,0,56,0,52,0,52,0,49,-1,-1,0,0,11,-108,-63,-112,83,-112,-24,117,53,82,-95,123,-95,116,6,79,-31,96,111,124,-5,126,-33,0,11,-108,-63,-112,83,-112,-24,117,53,82,-95,123,-95,116,6,79,-31,96,111,124,-5,126,-33,0,0,0,14,81,-123,-112,-24,95,0,83,-47,79,127,117,40,0,44,78,37,121,-127,79,32,100,-83,78,14,-107,0,85,46,0,7,0,87,0,105,0,110,0,100,0,111,0,119,0,115,0,0,
				0,0,1,26,68,-37,72,24,
    			0,0,0,1,-1,-1,-1,-1,0,11,0,50,0,48,0,48,0,48,0,32,0,45,0,32,0,50,0,48,0,48,0,54};
	*/
	}
	
	public static void main(String[] args) throws Exception, ParseException{
		//System.out11.println(fromDate2String("2008-09-20"));
//		ExtCellSet ecs = ExtCellSet._$1(new RSA().process(null));
//		int i=0;
	}
	
    private static String fromDate2String(String date) throws IOException, ParseException{
		File f = File.createTempFile("csmis", "report");
    	RandomAccessFile in = new RandomAccessFile(f,"rw");
	    in.seek(0);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    in.writeLong(sdf.parse(date+" 23:59:59").getTime());
	    in.seek(0);
	    byte[] bs = new byte[8];
	    in.read(bs);
	    in.close();
	    f.delete();
	    StringBuffer sb = new StringBuffer();
	    for(int i=0;i<bs.length;i++){
	    	sb.append(bs[i]).append(",");
	    }
	    return sb.toString();
    }
	private boolean _$1 = false;

	private BigInteger _$2;

	private BigInteger _$3;

	private int _$4;

	private int _$5;

	private static byte[] _$1(byte[] is) {
		int i = is.length;
		int i_0_ = i * 8 / 7;
		if (i % 7 != 0)
			i_0_++;
		byte[] is_1_ = new byte[i_0_];
		int i_2_ = 0;
		int i_3_ = 0;
		int i_4_ = 0;
		for (int i_5_ = 0; i_5_ < i; i_5_++) {
			int i_6_ = (is[i_5_] & 0xff) >> i_3_ + 1 | i_4_ << 7 - i_3_ | 0x80;
			is_1_[i_2_++] = (byte) i_6_;
			// boolean bool = is[i_5_] & 255 >> 7 - i_3_;
			i_4_ = (byte) is[i_5_] & 255 >> 7 - i_3_;
			if (++i_3_ % 7 == 0) {
				i_3_ = 0;
				is_1_[i_2_++] = (byte) (i_4_ | 0x80);
				i_4_ = 0;
			} else if (i_5_ == i - 1) {
				i_6_ = (is[i_5_] & 0xff) << 7 - i_3_ | 0x80;
				is_1_[i_2_] = (byte) i_6_;
			}
		}
		return is_1_;
	}

	private byte[] _$1(byte[] is, int i, int i_7_) {
		byte[] is_8_ = new byte[i_7_];
		System.arraycopy(is, i, is_8_, 0, i_7_);
		Object object = new BigInteger(1, is_8_);
		byte[] is_9_ = ((BigInteger) object).modPow(_$3, _$2).toByteArray();
		if (_$1) {
			if (is_9_[0] == 0 && is_9_.length > _$5) {
				byte[] is_10_ = new byte[is_9_.length - 1];
				System.arraycopy(is_9_, 1, is_10_, 0, is_10_.length);
				is_9_ = is_10_;
			} else if (is_9_.length < _$5) {
				byte[] is_11_ = new byte[_$5];
				System.arraycopy(is_9_, 0, is_11_, is_11_.length - is_9_.length, is_9_.length);
				is_9_ = is_11_;
			}
		} else if (is_9_[0] == 0) {
			byte[] is_12_ = new byte[is_9_.length - 1];
			System.arraycopy(is_9_, 1, is_12_, 0, is_12_.length);
			is_9_ = is_12_;
		}
		return is_9_;
	}

	private static byte[] _$2(byte[] is) {
		int i = is.length;
		byte[] is_13_ = new byte[i * 7 / 8];
		int i_14_ = 0;
		int i_15_ = 0;
		for (int i_17_ = 0; i_17_ < i - 1; i_17_++) {
			int i_18_ = ((is[i_17_] & 0x7f) << i_15_ + 1 | (is[i_17_ + 1] & 0x7f) >> 6 - i_15_);
			is_13_[i_14_++] = (byte) i_18_;
			if (++i_15_ % 7 == 0) {
				i_15_ = 0;
				i_17_++;
			}
		}
		return is_13_;
	}

	public void init(boolean bool, BigInteger biginteger, BigInteger biginteger_19_) {
		_$1 = bool;
		_$2 = biginteger;
		_$3 = biginteger_19_;
		int i = biginteger.bitLength();
		if (bool) {
			_$4 = (i + 7) / 8 - 1;
			_$5 = (i + 7) / 8;
		} else {
			_$4 = (i + 7) / 8;
			_$5 = (i + 7) / 8 - 1;
		}
	}

}

class CredWriter{
	
	private ByteArrayOutputStream out = new ByteArrayOutputStream();
	
	public String writeByte(int arg){
		out.write(arg);
		return ","+arg;
	}

	public String writeChar(int arg){
		return writeShort(arg);
	}

	public String writeShort(int arg){
		out.write(arg>>8);
		out.write(arg%256);
		return ","+(arg>>8)+","+(arg%256);
	}

	public String writeLong(long arg){
		out.write((int)arg>>56%256);
		out.write((int)arg>>48%256);
		out.write((int)arg>>40%256);
		out.write((int)arg>>32%256);
		out.write((int)arg>>24%256);
		out.write((int)arg>>16%256);
		out.write((int)arg>>8%256);
		out.write((int)arg%256);
		return ","+(arg>>24%256)+","+(arg>>16%256)+","+(arg>>8%256)+","+(arg%256);
	}

	public String writeChars(String arg){
		String tmp = this.writeShort(arg.length());
		for(int i=0;i<arg.length();i++){
			tmp += this.writeChar(arg.charAt(i));
		}
		return tmp;
	}

	public byte[] getBytes(){
		return out.toByteArray();
	}

}